1. Project Clover database Tue Apr 9 2024 16:11:52 CDT
  2. Package com.alibaba.fastjson

File JSON.java

 
test_4: setter not found, class com.alibaba.json.bvt.parser.JSONS...
test_singleQuote: syntax error
test_bigdecimal: Feature.AllowSingleQuotes is false
test_1: Feature.AllowSingleQuotes is false
test_time: parse error
test_f: syntax error
test_null: syntax error
test_b: setter not found, class com.alibaba.json.bvt.parser.JSONL...
test_SecurityContextImpl_x: setter not found, class org.springframework.security.auth...
test_1: Feature.AllowSingleQuotes is false
test_11: syntax error
test_47: syntax error
test_map: Feature.AllowSingleQuotes is false
test_bigdecimal: Feature.AllowSingleQuotes is false
test_6: syntax error
test_feature2: setter not found, class com.alibaba.json.bvt.feature.Disa...
test_for_issue: Feature.AllowSingleQuotes is false
test_0: Feature.AllowSingleQuotes is false
test_1: syntax error
test_7: syntax error
test_34: syntax error
test_sqlDate: For input string: "2024-04-10 05:38:09"
test_for_issue: setter not found, class com.alibaba.json.bvt.bug.Bug_for_...
test_singleQuote_vo: syntax error
test_url: Feature.AllowSingleQuotes is false
test_8: syntax error
test_special_browsecue: syntax error
test_2: Feature.AllowSingleQuotes is false
test_0: syntax error
test_for_ludong: setter not found, class com.alibaba.json.bvt.bug.Bug_for_...
test_for_issue: setter not found, class org.springframework.security.web....
test_feature2: setter not found, class com.alibaba.json.bvt.feature.Disa...
test_for_issue_true: setter not found, class com.alibaba.json.bvt.bug.Issue939...
test_7: syntax error
test_notMatch: setter not found, class com.alibaba.json.bvt.parser.deser...
test_strings: Feature.AllowSingleQuotes is false
test_enums: Feature.AllowSingleQuotes is false
test_string_2: Feature.AllowSingleQuotes is false
test_notMatch: setter not found, class com.alibaba.json.bvt.parser.deser...
test_for_bug: syntax error
test_matchField: setter not found, class com.alibaba.json.bvt.parser.JSONL...
test_enum_2: Feature.AllowSingleQuotes is false
test_for_bug: setter not found, class com.alibaba.json.bvt.parser.bug.B...
test_user: setter not found, class kotlin.ranges.IntRange, property end
test_for_issue: setter not found, class com.alibaba.json.bvt.bug.Bug_for_...
test_12: syntax error
test_PreAuthenticatedAuthenticationToken: setter not found, class org.springframework.security.web....
test_2: syntax error
test_f: syntax error
test_f: syntax error
test_bigdecimal: Feature.AllowSingleQuotes is false
test_final: setter not found, class com.alibaba.json.bvt.FinalTest$VO...
test_for_issue: setter not found, class com.alibaba.json.bvt.issue_2300.I...
test_4: syntax error
test_for_issue_1188: setter not found, class com.alibaba.json.bvt.issue_1100.I...
test: setter not found, class com.alibaba.json.bvt.bug.Bug_for_...
test_0: setter not found, class com.alibaba.json.bvt.TestFlase$VO...
test_2: setter not found, class com.alibaba.json.bvt.parser.JSONS...
test_2: Feature.AllowSingleQuotes is false
test_deserializeUsing: syntax error
test_extraWithType: setter not found, class com.alibaba.json.bvt.parser.Redun...
test_feature: setter not found, class com.alibaba.json.bvt.feature.Disa...
test_for_issue: setter not found, class com.alibaba.json.bvt.bug.Bug_for_...
test_1: Feature.AllowSingleQuotes is false
test_0: setter not found, class com.alibaba.json.bvtVO.DataTransa...
test_for_wangran: setter not found, class com.alibaba.json.bvtVO.QueueEntit...
test_date_5: Feature.AllowSingleQuotes is false
test_6: syntax error
test_13: syntax error
test_strings_: Feature.AllowSingleQuotes is false
test_0: Feature.AllowSingleQuotes is false
test_parse: Feature.AllowSingleQuotes is false
test_for_issue: setter not found, class com.alibaba.json.bvt.bug.Bug_for_...
test_for_issue: setter not found, class com.alibaba.json.bvt.issue_1200.I...
test_generic: Feature.AllowSingleQuotes is false
test_parseObject_2: setter not found, class com.alibaba.json.bvt.issue_1200.I...
test_f: syntax error
test_1: syntax error
test_long_list: setter not found, class com.alibaba.json.bvt.parser.bug.B...
test_3: syntax error
test_1: Feature.AllowSingleQuotes is false
test_for_issue: setter not found, class com.alibaba.json.bvt.issue_1300.I...
test_1: Feature.AllowSingleQuotes is false
test_bigdecimal: Feature.AllowSingleQuotes is false
test_bigdecimal: Feature.AllowSingleQuotes is false
test_1: syntax error
test_notMatch: setter not found, class com.alibaba.json.bvt.parser.deser...
test_2: Feature.AllowSingleQuotes is false
test_for_issue: syntax error
test_2: Feature.AllowSingleQuotes is false
test_value2: setter not found, class com.alibaba.json.bvt.parser.JSONL...
test_url: Feature.AllowSingleQuotes is false
test_date: Feature.AllowSingleQuotes is false
test_for_issue: setter not found, class com.alibaba.json.bvt.issue_1500.I...
test_9: syntax error
test_extra: setter not found, class com.alibaba.json.bvt.parser.Redun...
test_strings_2: Feature.AllowSingleQuotes is false
test_2: setter not found, class com.alibaba.json.bvt.parser.JSONS...
test_pattern: Feature.AllowSingleQuotes is false
test_e: Feature.AllowSingleQuotes is false
test_enum_error: Feature.AllowSingleQuotes is false
test_0: setter not found, class com.alibaba.json.bvt.bug.Bug_for_...
test_1: Feature.AllowSingleQuotes is false
test_bigdecimal: Feature.AllowSingleQuotes is false
test_5: syntax error
test_enum: Feature.AllowSingleQuotes is false
test_utf8: syntax error
test_dup: setter not found, class com.alibaba.json.bvt.parser.deser...
test_feature: setter not found, class com.alibaba.json.bvt.feature.Disa...
test_92: syntax error
test_bytes: Feature.AllowSingleQuotes is false
test_boolean: Feature.AllowSingleQuotes is false
test_for_issue_false: setter not found, class com.alibaba.json.bvt.bug.Issue939...
test_for_issue: setter not found, class com.alibaba.json.bvt.issue_2000.I...
test_8: syntax error
test_for_issue: setter not found, class com.alibaba.json.bvt.bug.Bug_for_...
test_for_issue: setter not found, class com.alibaba.json.bvt.issue_1200.I...
test_value: Feature.AllowSingleQuotes is false
test: setter not found, class cn.com.tx.domain.pagination.Pagin...
test_for_issue: setter not found, class com.alibaba.json.bvt.issue_1200.I...
test_date_7: Feature.AllowSingleQuotes is false
test_for_issue: setter not found, class com.alibaba.json.bvt.bug.Bug_for_...
test_39: syntax error
test_0: setter not found, class org.springframework.security.oaut...
test_date: parseLong error, field : value
test_0: syntax error
test_10: syntax error
test_0: Feature.AllowSingleQuotes is false
test_for_maiksagill: setter not found, class com.alibaba.json.bvtVO.Image, pro...
test_for_issue: setter not found, class com.alibaba.json.bvtVO.ae.huangli...
test_for_wangran: setter not found, class com.alibaba.json.bvtVO.VirtualTop...
test_charArray: syntax error
test_utf: syntax error
test_for_issue_decode: setter not found, class com.alibaba.json.bvt.bug.Bug_for_...
 

Coverage histogram

../../../img/srcFileCovDistChart10.png
0% of files have more coverage

Code metrics

138
440
87
1
1,288
875
185
0.42
5.06
87
2.13

Classes

Class Line # Actions
JSON 67 440 0% 185 48
0.9278195592.8%
 

Contributing tests

This file is covered by 4050 tests. .

Source view

1    /*
2    * Copyright 1999-2017 Alibaba Group.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.apache.org/licenses/LICENSE-2.0
9    *
10    * Unless required by applicable law or agreed to in writing, software
11    * distributed under the License is distributed on an "AS IS" BASIS,
12    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13    * See the License for the specific language governing permissions and
14    * limitations under the License.
15    */
16    package com.alibaba.fastjson;
17   
18    import java.io.IOException;
19    import java.io.InputStream;
20    import java.io.OutputStream;
21    import java.io.Writer;
22    import java.lang.reflect.Array;
23    import java.lang.reflect.Type;
24    import java.nio.ByteBuffer;
25    import java.nio.CharBuffer;
26    import java.nio.charset.Charset;
27    import java.nio.charset.CharsetDecoder;
28    import java.util.*;
29    import java.util.concurrent.ConcurrentHashMap;
30   
31    import com.alibaba.fastjson.parser.*;
32    import com.alibaba.fastjson.parser.deserializer.ExtraProcessor;
33    import com.alibaba.fastjson.parser.deserializer.ExtraTypeProvider;
34    import com.alibaba.fastjson.parser.deserializer.FieldTypeResolver;
35    import com.alibaba.fastjson.parser.deserializer.ParseProcess;
36    import com.alibaba.fastjson.serializer.*;
37    import com.alibaba.fastjson.util.IOUtils;
38    import com.alibaba.fastjson.util.IdentityHashMap;
39    import com.alibaba.fastjson.util.TypeUtils;
40   
41    /**
42    * This is the main class for using Fastjson. You usually call these two methods {@link #toJSONString(Object)} and {@link #parseObject(String, Class)}.
43    *
44    * <p>Here is an example of how fastjson is used for a simple Class:
45    *
46    * <pre>
47    * Model model = new Model();
48    * String json = JSON.toJSONString(model); // serializes model to Json
49    * Model model2 = JSON.parseObject(json, Model.class); // deserializes json into model2
50    * </pre>
51    *
52    * <p>If the object that your are serializing/deserializing is a {@code ParameterizedType}
53    * (i.e. contains at least one type parameter and may be an array) then you must use the
54    * {@link #toJSONString(Object)} or {@link #parseObject(String, Type, Feature[])} method. Here is an
55    * example for serializing and deserialing a {@code ParameterizedType}:
56    *
57    * <pre>
58    * String json = "[{},...]";
59    * Type listType = new TypeReference&lt;List&lt;Model&gt;&gt;() {}.getType();
60    * List&lt;Model&gt; modelList = JSON.parseObject(json, listType);
61    * </pre>
62    *
63    * @see com.alibaba.fastjson.TypeReference
64    *
65    * @author wenshao[szujobs@hotmail.com]
66    */
 
67    public abstract class JSON implements JSONStreamAware, JSONAware {
68    public static TimeZone defaultTimeZone = TimeZone.getDefault();
69    public static Locale defaultLocale = Locale.getDefault();
70    public static String DEFAULT_TYPE_KEY = "@type";
71    static final SerializeFilter[] emptyFilters = new SerializeFilter[0];
72    public static String DEFFAULT_DATE_FORMAT = "yyyy-MM-dd HH:mm:ss";
73    public static int DEFAULT_PARSER_FEATURE;
74    public static int DEFAULT_GENERATE_FEATURE;
75   
76    private static final ConcurrentHashMap<Type, Type> mixInsMapper = new ConcurrentHashMap<Type, Type>(16);
77   
 
78  1 toggle static {
79  1 int features = 0;
80  1 features |= Feature.AutoCloseSource.getMask();
81  1 features |= Feature.InternFieldNames.getMask();
82  1 features |= Feature.UseBigDecimal.getMask();
83  1 features |= Feature.AllowUnQuotedFieldNames.getMask();
84  1 features |= Feature.AllowSingleQuotes.getMask();
85  1 features |= Feature.AllowArbitraryCommas.getMask();
86  1 features |= Feature.SortFeidFastMatch.getMask();
87  1 features |= Feature.IgnoreNotMatch.getMask();
88  1 DEFAULT_PARSER_FEATURE = features;
89    }
90   
 
91  1 toggle static {
92  1 int features = 0;
93  1 features |= SerializerFeature.QuoteFieldNames.getMask();
94  1 features |= SerializerFeature.SkipTransientField.getMask();
95  1 features |= SerializerFeature.WriteEnumUsingName.getMask();
96  1 features |= SerializerFeature.SortField.getMask();
97   
98  1 DEFAULT_GENERATE_FEATURE = features;
99   
100  1 config(IOUtils.DEFAULT_PROPERTIES);
101    }
102   
 
103  1 toggle private static void config(Properties properties) {
104    {
105  1 String featuresProperty = properties.getProperty("fastjson.serializerFeatures.MapSortField");
106  1 int mask = SerializerFeature.MapSortField.getMask();
107  1 if ("true".equals(featuresProperty)) {
108  0 DEFAULT_GENERATE_FEATURE |= mask;
109  1 } else if ("false".equals(featuresProperty)) {
110  0 DEFAULT_GENERATE_FEATURE &= ~mask;
111    }
112    }
113   
114    {
115  1 if ("true".equals(properties.getProperty("parser.features.NonStringKeyAsString"))) {
116  0 DEFAULT_PARSER_FEATURE |= Feature.NonStringKeyAsString.getMask();
117    }
118    }
119   
120    {
121  1 if ("true".equals(properties.getProperty("parser.features.ErrorOnEnumNotMatch"))
122    || "true".equals(properties.getProperty("fastjson.parser.features.ErrorOnEnumNotMatch")))
123    {
124  0 DEFAULT_PARSER_FEATURE |= Feature.ErrorOnEnumNotMatch.getMask();
125    }
126    }
127   
128    {
129  1 if ("false".equals(properties.getProperty("fastjson.asmEnable"))) {
130  0 ParserConfig.getGlobalInstance().setAsmEnable(false);
131  0 SerializeConfig.getGlobalInstance().setAsmEnable(false);
132    }
133    }
134    }
135   
136    /**
137    * config default type key
138    * @since 1.2.14
139    */
 
140  2 toggle public static void setDefaultTypeKey(String typeKey) {
141  2 DEFAULT_TYPE_KEY = typeKey;
142  2 ParserConfig.global.symbolTable.addSymbol(typeKey,
143    0,
144    typeKey.length(),
145    typeKey.hashCode(), true);
146    }
147   
 
148  5021112 toggle public static Object parse(String text) {
149  5021112 Test failure here return parse(text, DEFAULT_PARSER_FEATURE);
150    }
151   
152    /**
153    *
154    * @since 1.2.38
155    */
 
156  7 toggle public static Object parse(String text, ParserConfig config) {
157  7 return parse(text, config, DEFAULT_PARSER_FEATURE);
158    }
159   
160    /**
161    *
162    * @since 1.2.38
163    */
 
164  5025217 toggle public static Object parse(String text, ParserConfig config, int features) {
165  5025217 if (text == null) {
166  4 return null;
167    }
168   
169  5025213 DefaultJSONParser parser = new DefaultJSONParser(text, config, features);
170  5025207 Test failure here Object value = parser.parse();
171   
172  5025113 parser.handleResovleTask(value);
173   
174  5025113 parser.close();
175   
176  5025113 return value;
177    }
178   
 
179  5025202 toggle public static Object parse(String text, int features) {
180  5025202 Test failure here return parse(text, ParserConfig.getGlobalInstance(), features);
181    }
182   
 
183  14 toggle public static Object parse(byte[] input, Feature... features) {
184  14 char[] chars = allocateChars(input.length);
185  14 int len = IOUtils.decodeUTF8(input, 0, input.length, chars);
186  14 if (len < 0) {
187  0 return null;
188    }
189  14 Test failure here return parse(new String(chars, 0, len), features);
190    }
191   
 
192  5 toggle public static Object parse(byte[] input, int off, int len, CharsetDecoder charsetDecoder, Feature... features) {
193  5 if (input == null || input.length == 0) {
194  2 return null;
195    }
196   
197  3 int featureValues = DEFAULT_PARSER_FEATURE;
198  3 for (Feature feature : features) {
199  11 featureValues = Feature.config(featureValues, feature, true);
200    }
201   
202  3 return parse(input, off, len, charsetDecoder, featureValues);
203    }
204   
 
205  5 toggle public static Object parse(byte[] input, int off, int len, CharsetDecoder charsetDecoder, int features) {
206  5 charsetDecoder.reset();
207   
208  3 int scaleLength = (int) (len * (double) charsetDecoder.maxCharsPerByte());
209  3 char[] chars = allocateChars(scaleLength);
210   
211  3 ByteBuffer byteBuf = ByteBuffer.wrap(input, off, len);
212  3 CharBuffer charBuf = CharBuffer.wrap(chars);
213  3 IOUtils.decode(charsetDecoder, byteBuf, charBuf);
214   
215  3 int position = charBuf.position();
216   
217  3 DefaultJSONParser parser = new DefaultJSONParser(chars, position, ParserConfig.getGlobalInstance(), features);
218  3 Object value = parser.parse();
219   
220  3 parser.handleResovleTask(value);
221   
222  3 parser.close();
223   
224  3 return value;
225    }
226   
 
227  4088 toggle public static Object parse(String text, Feature... features) {
228  4088 int featureValues = DEFAULT_PARSER_FEATURE;
229  4088 for (Feature feature : features) {
230  4061 featureValues = Feature.config(featureValues, feature, true);
231    }
232   
233  4084 Test failure here return parse(text, featureValues);
234    }
235   
 
236  45 toggle public static JSONObject parseObject(String text, Feature... features) {
237  45 Test failure here return (JSONObject) parse(text, features);
238    }
239   
 
240  4000288 toggle public static JSONObject parseObject(String text) {
241  4000288 Test failure here Object obj = parse(text);
242  4000258 if (obj instanceof JSONObject) {
243  4000247 return (JSONObject) obj;
244    }
245   
246  11 try {
247  11 return (JSONObject) JSON.toJSON(obj);
248    } catch (RuntimeException e) {
249  1 throw new JSONException("can not cast to JSONObject.", e);
250    }
251    }
252   
253    /**
254    * <pre>
255    * String jsonStr = "[{\"id\":1001,\"name\":\"Jobs\"}]";
256    * List&lt;Model&gt; models = JSON.parseObject(jsonStr, new TypeReference&lt;List&lt;Model&gt;&gt;() {});
257    * </pre>
258    * @param text json string
259    * @param type type refernce
260    * @param features
261    * @return
262    */
 
263  365 toggle @SuppressWarnings("unchecked")
264    public static <T> T parseObject(String text, TypeReference<T> type, Feature... features) {
265  365 Test failure here return (T) parseObject(text, type.type, ParserConfig.global, DEFAULT_PARSER_FEATURE, features);
266    }
267   
268    /**
269    *
270    * This method deserializes the specified Json into an object of the specified class. It is not
271    * suitable to use if the specified class is a generic type since it will not have the generic
272    * type information because of the Type Erasure feature of Java. Therefore, this method should not
273    * be used if the desired type is a generic type. Note that this method works fine if the any of
274    * the fields of the specified object are generics, just the object itself should not be a
275    * generic type. For the cases when the object is of generic type, invoke
276    * {@link #parseObject(String, Type, Feature[])}. If you have the Json in a {@link InputStream} instead of
277    * a String, use {@link #parseObject(InputStream, Type, Feature[])} instead.
278    *
279    * @param json the string from which the object is to be deserialized
280    * @param clazz the class of T
281    * @param features parser features
282    * @return an object of type T from the string
283    * classOfT
284    */
 
285  15030269 toggle @SuppressWarnings("unchecked")
286    public static <T> T parseObject(String json, Class<T> clazz, Feature... features) {
287  15030269 Test failure here return (T) parseObject(json, (Type) clazz, ParserConfig.global, null, DEFAULT_PARSER_FEATURE, features);
288    }
289   
 
290  4 toggle @SuppressWarnings("unchecked")
291    public static <T> T parseObject(String text, Class<T> clazz, ParseProcess processor, Feature... features) {
292  4 Test failure here return (T) parseObject(text, (Type) clazz, ParserConfig.global, processor, DEFAULT_PARSER_FEATURE,
293    features);
294    }
295   
296    /**
297    * This method deserializes the specified Json into an object of the specified type. This method
298    * is useful if the specified object is a generic type. For non-generic objects, use
299    * {@link #parseObject(String, Class, Feature[])} instead. If you have the Json in a {@link InputStream} instead of
300    * a String, use {@link #parseObject(InputStream, Type, Feature[])} instead.
301    *
302    * @param <T> the type of the desired object
303    * @param json the string from which the object is to be deserialized
304    * @param type The specific genericized type of src. You can obtain this type by using the
305    * {@link com.alibaba.fastjson.TypeReference} class. For example, to get the type for
306    * {@code Collection<Foo>}, you should use:
307    * <pre>
308    * Type type = new TypeReference&lt;Collection&lt;Foo&gt;&gt;(){}.getType();
309    * </pre>
310    * @return an object of type T from the string
311    */
 
312  27 toggle @SuppressWarnings("unchecked")
313    public static <T> T parseObject(String json, Type type, Feature... features) {
314  27 Test failure here return (T) parseObject(json, type, ParserConfig.global, DEFAULT_PARSER_FEATURE, features);
315    }
316   
 
317  5 toggle @SuppressWarnings("unchecked")
318    public static <T> T parseObject(String input, Type clazz, ParseProcess processor, Feature... features) {
319  5 return (T) parseObject(input, clazz, ParserConfig.global, processor, DEFAULT_PARSER_FEATURE, features);
320    }
321   
 
322  15 toggle @SuppressWarnings("unchecked")
323    public static <T> T parseObject(String input, Type clazz, int featureValues, Feature... features) {
324  15 if (input == null) {
325  1 return null;
326    }
327   
328  14 for (Feature feature : features) {
329  8 featureValues = Feature.config(featureValues, feature, true);
330    }
331   
332  14 DefaultJSONParser parser = new DefaultJSONParser(input, ParserConfig.getGlobalInstance(), featureValues);
333  14 T value = (T) parser.parseObject(clazz);
334   
335  9 parser.handleResovleTask(value);
336   
337  9 parser.close();
338   
339  9 return (T) value;
340    }
341   
342    /**
343    * @since 1.2.11
344    */
 
345  54 toggle public static <T> T parseObject(String input, Type clazz, ParserConfig config, Feature... features) {
346  54 Test failure here return parseObject(input, clazz, config, null, DEFAULT_PARSER_FEATURE, features);
347    }
348   
 
349  421 toggle public static <T> T parseObject(String input, Type clazz, ParserConfig config, int featureValues,
350    Feature... features) {
351  421 Test failure here return parseObject(input, clazz, config, null, featureValues, features);
352    }
353   
 
354  15030822 toggle @SuppressWarnings("unchecked")
355    public static <T> T parseObject(String input, Type clazz, ParserConfig config, ParseProcess processor,
356    int featureValues, Feature... features) {
357  15030822 if (input == null) {
358  4 return null;
359    }
360   
361  15030818 if (features != null) {
362  15030816 for (Feature feature : features) {
363  12000168 featureValues |= feature.mask;
364    }
365    }
366   
367  15030818 Test failure here DefaultJSONParser parser = new DefaultJSONParser(input, config, featureValues);
368   
369  15030794 if (processor != null) {
370  4 if (processor instanceof ExtraTypeProvider) {
371  0 parser.getExtraTypeProviders().add((ExtraTypeProvider) processor);
372    }
373   
374  5 if (processor instanceof ExtraProcessor) {
375  4 parser.getExtraProcessors().add((ExtraProcessor) processor);
376    }
377   
378  5 if (processor instanceof FieldTypeResolver) {
379  1 parser.setFieldTypeResolver((FieldTypeResolver) processor);
380    }
381    }
382   
383  15030794 Test failure here T value = (T) parser.parseObject(clazz, null);
384   
385  15030437 parser.handleResovleTask(value);
386   
387  15030437 parser.close();
388   
389  15030434 return (T) value;
390    }
391   
 
392  5 toggle @SuppressWarnings("unchecked")
393    public static <T> T parseObject(byte[] bytes, Type clazz, Feature... features) {
394  5 Test failure here return (T) parseObject(bytes, 0, bytes.length, IOUtils.UTF8, clazz, features);
395    }
396   
397    /**
398    * @since 1.2.11
399    */
 
400  9 toggle @SuppressWarnings("unchecked")
401    public static <T> T parseObject(byte[] bytes, int offset, int len, Charset charset, Type clazz, Feature... features) {
402  9 Test failure here return (T) parseObject(bytes, offset, len, charset, clazz, ParserConfig.global, null, DEFAULT_PARSER_FEATURE, features);
403    }
404   
405    /**
406    * @since 1.2.55
407    */
 
408  6 toggle @SuppressWarnings("unchecked")
409    public static <T> T parseObject(byte[] bytes,
410    Charset charset,
411    Type clazz,
412    ParserConfig config,
413    ParseProcess processor,
414    int featureValues,
415    Feature... features) {
416  6 return (T) parseObject(bytes, 0, bytes.length, charset, clazz, config, processor, featureValues, features);
417    }
418   
419    /**
420    * @since 1.2.55
421    */
 
422  67 toggle @SuppressWarnings("unchecked")
423    public static <T> T parseObject(byte[] bytes, int offset, int len,
424    Charset charset,
425    Type clazz,
426    ParserConfig config,
427    ParseProcess processor,
428    int featureValues,
429    Feature... features) {
430  67 if (charset == null) {
431  6 charset = IOUtils.UTF8;
432    }
433   
434  67 String strVal;
435  67 if (charset == IOUtils.UTF8) {
436  67 char[] chars = allocateChars(bytes.length);
437  67 int chars_len = IOUtils.decodeUTF8(bytes, offset, len, chars);
438  67 if (chars_len < 0) {
439  1 return null;
440    }
441  66 strVal = new String(chars, 0, chars_len);
442    } else {
443  0 if (len < 0) {
444  0 return null;
445    }
446  0 strVal = new String(bytes, offset, len, charset);
447    }
448  66 Test failure here return (T) parseObject(strVal, clazz, config, processor, featureValues, features);
449    }
450   
 
451  5 toggle @SuppressWarnings("unchecked")
452    public static <T> T parseObject(byte[] input, //
453    int off, //
454    int len, //
455    CharsetDecoder charsetDecoder, //
456    Type clazz, //
457    Feature... features) {
458  5 charsetDecoder.reset();
459   
460  1 int scaleLength = (int) (len * (double) charsetDecoder.maxCharsPerByte());
461  1 char[] chars = allocateChars(scaleLength);
462   
463  1 ByteBuffer byteBuf = ByteBuffer.wrap(input, off, len);
464  1 CharBuffer charByte = CharBuffer.wrap(chars);
465  1 IOUtils.decode(charsetDecoder, byteBuf, charByte);
466   
467  1 int position = charByte.position();
468   
469  1 return (T) parseObject(chars, position, clazz, features);
470    }
471   
 
472  7 toggle @SuppressWarnings("unchecked")
473    public static <T> T parseObject(char[] input, int length, Type clazz, Feature... features) {
474  7 if (input == null || input.length == 0) {
475  2 return null;
476    }
477   
478  5 int featureValues = DEFAULT_PARSER_FEATURE;
479  5 for (Feature feature : features) {
480  3 featureValues = Feature.config(featureValues, feature, true);
481    }
482   
483  3 DefaultJSONParser parser = new DefaultJSONParser(input, length, ParserConfig.getGlobalInstance(), featureValues);
484  3 T value = (T) parser.parseObject(clazz);
485   
486  3 parser.handleResovleTask(value);
487   
488  3 parser.close();
489   
490  3 return (T) value;
491    }
492   
493    /**
494    * @since 1.2.11
495    */
 
496  2 toggle @SuppressWarnings("unchecked")
497    public static <T> T parseObject(InputStream is, //
498    Type type, //
499    Feature... features) throws IOException {
500  2 return (T) parseObject(is, IOUtils.UTF8, type, features);
501    }
502   
503    /**
504    * @since 1.2.11
505    */
 
506  2 toggle @SuppressWarnings("unchecked")
507    public static <T> T parseObject(InputStream is, //
508    Charset charset, //
509    Type type, //
510    Feature... features) throws IOException {
511  2 return (T) parseObject(is, charset, type, ParserConfig.global, features);
512    }
513   
514    /**
515    * @since 1.2.55
516    */
 
517  2 toggle @SuppressWarnings("unchecked")
518    public static <T> T parseObject(InputStream is, //
519    Charset charset, //
520    Type type, //
521    ParserConfig config, //
522    Feature... features) throws IOException {
523  2 return (T) parseObject(is, charset, type, config, null, DEFAULT_PARSER_FEATURE, features);
524    }
525   
526    /**
527    * @since 1.2.55
528    */
 
529  56 toggle @SuppressWarnings("unchecked")
530    public static <T> T parseObject(InputStream is, //
531    Charset charset, //
532    Type type, //
533    ParserConfig config, //
534    ParseProcess processor, //
535    int featureValues, //
536    Feature... features) throws IOException {
537  56 if (charset == null) {
538  2 charset = IOUtils.UTF8;
539    }
540   
541  56 byte[] bytes = allocateBytes(1024 * 64);
542  56 int offset = 0;
543  56 for (;;) {
544  108 int readCount = is.read(bytes, offset, bytes.length - offset);
545  104 if (readCount == -1) {
546  52 break;
547    }
548  52 offset += readCount;
549  52 if (offset == bytes.length) {
550  0 byte[] newBytes = new byte[bytes.length * 3 / 2];
551  0 System.arraycopy(bytes, 0, newBytes, 0, bytes.length);
552  0 bytes = newBytes;
553    }
554    }
555   
556  52 return (T) parseObject(bytes, 0, offset, charset, type, config, processor, featureValues, features);
557    }
558   
 
559  3030115 toggle public static <T> T parseObject(String text, Class<T> clazz) {
560  3030115 Test failure here return parseObject(text, clazz, new Feature[0]);
561    }
562   
 
563  42 toggle public static JSONArray parseArray(String text) {
564  42 if (text == null) {
565  2 return null;
566    }
567   
568  40 DefaultJSONParser parser = new DefaultJSONParser(text, ParserConfig.getGlobalInstance());
569   
570  40 JSONArray array;
571   
572  40 JSONLexer lexer = parser.lexer;
573  40 if (lexer.token() == JSONToken.NULL) {
574  2 lexer.nextToken();
575  2 array = null;
576  38 } else if (lexer.token() == JSONToken.EOF) {
577  3 array = null;
578    } else {
579  35 array = new JSONArray();
580  35 Test failure here parser.parseArray(array);
581   
582  33 parser.handleResovleTask(array);
583    }
584   
585  38 parser.close();
586   
587  38 return array;
588    }
589   
 
590  39 toggle public static <T> List<T> parseArray(String text, Class<T> clazz) {
591  39 if (text == null) {
592  1 return null;
593    }
594   
595  38 List<T> list;
596   
597  38 DefaultJSONParser parser = new DefaultJSONParser(text, ParserConfig.getGlobalInstance());
598  38 JSONLexer lexer = parser.lexer;
599  38 int token = lexer.token();
600  38 if (token == JSONToken.NULL) {
601  8 lexer.nextToken();
602  8 list = null;
603  30 } else if (token == JSONToken.EOF && lexer.isBlankInput()) {
604  1 list = null;
605    } else {
606  29 list = new ArrayList<T>();
607  29 Test failure here parser.parseArray(clazz, list);
608   
609  26 parser.handleResovleTask(list);
610    }
611   
612  35 parser.close();
613   
614  35 return list;
615    }
616   
 
617  15 toggle public static List<Object> parseArray(String text, Type[] types) {
618  15 if (text == null) {
619  1 return null;
620    }
621   
622  14 List<Object> list;
623   
624  14 DefaultJSONParser parser = new DefaultJSONParser(text, ParserConfig.getGlobalInstance());
625  14 Object[] objectArray = parser.parseArray(types);
626  12 if (objectArray == null) {
627  1 list = null;
628    } else {
629  11 list = Arrays.asList(objectArray);
630    }
631   
632  12 parser.handleResovleTask(list);
633   
634  12 parser.close();
635   
636  12 return list;
637    }
638   
639    /**
640    * This method serializes the specified object into its equivalent Json representation. Note that this method works fine if the any of the object fields are of generic type,
641    * just the object itself should not be of a generic type. If you want to write out the object to a
642    * {@link Writer}, use {@link #writeJSONString(Writer, Object, SerializerFeature[])} instead.
643    *
644    * @param object the object for which json representation is to be created setting for fastjson
645    * @return Json representation of {@code object}.
646    */
 
647  7029537 toggle public static String toJSONString(Object object) {
648  7029537 return toJSONString(object, emptyFilters);
649    }
650   
 
651  12002045 toggle public static String toJSONString(Object object, SerializerFeature... features) {
652  12002045 return toJSONString(object, DEFAULT_GENERATE_FEATURE, features);
653    }
654   
655    /**
656    * @since 1.2.11
657    */
 
658  12002049 toggle public static String toJSONString(Object object, int defaultFeatures, SerializerFeature... features) {
659  12002050 SerializeWriter out = new SerializeWriter((Writer) null, defaultFeatures, features);
660   
661  12002047 try {
662  12002047 JSONSerializer serializer = new JSONSerializer(out);
663  12002046 serializer.write(object);
664  12002045 return out.toString();
665    } finally {
666  12002046 out.close();
667    }
668    }
669   
670    /**
671    * @since 1.1.14
672    */
 
673  19 toggle public static String toJSONStringWithDateFormat(Object object, String dateFormat,
674    SerializerFeature... features) {
675  19 return toJSONString(object, SerializeConfig.globalInstance, null, dateFormat, DEFAULT_GENERATE_FEATURE, features);
676    }
677   
 
678  57 toggle public static String toJSONString(Object object, SerializeFilter filter, SerializerFeature... features) {
679  57 return toJSONString(object, SerializeConfig.globalInstance, new SerializeFilter[] {filter}, null, DEFAULT_GENERATE_FEATURE, features);
680    }
681   
 
682  7029609 toggle public static String toJSONString(Object object, SerializeFilter[] filters, SerializerFeature... features) {
683  7029609 return toJSONString(object, SerializeConfig.globalInstance, filters, null, DEFAULT_GENERATE_FEATURE, features);
684    }
685   
 
686  25 toggle public static byte[] toJSONBytes(Object object, SerializerFeature... features) {
687  25 return toJSONBytes(object, DEFAULT_GENERATE_FEATURE, features);
688    }
689   
 
690  17 toggle public static byte[] toJSONBytes(Object object, SerializeFilter filter, SerializerFeature... features) {
691  17 return toJSONBytes(object, SerializeConfig.globalInstance, new SerializeFilter[] {filter}, DEFAULT_GENERATE_FEATURE, features);
692    }
693   
694    /**
695    * @since 1.2.11
696    */
 
697  79 toggle public static byte[] toJSONBytes(Object object, int defaultFeatures, SerializerFeature... features) {
698  79 return toJSONBytes(object, SerializeConfig.globalInstance, defaultFeatures, features);
699    }
700   
 
701  218 toggle public static String toJSONString(Object object, SerializeConfig config, SerializerFeature... features) {
702  218 return toJSONString(object, config, (SerializeFilter) null, features);
703    }
704   
 
705  221 toggle public static String toJSONString(Object object, //
706    SerializeConfig config, //
707    SerializeFilter filter, //
708    SerializerFeature... features) {
709  221 return toJSONString(object, config, new SerializeFilter[] {filter}, null, DEFAULT_GENERATE_FEATURE, features);
710    }
711   
 
712  6 toggle public static String toJSONString(Object object, //
713    SerializeConfig config, //
714    SerializeFilter[] filters, //
715    SerializerFeature... features) {
716  6 return toJSONString(object, config, filters, null, DEFAULT_GENERATE_FEATURE, features);
717    }
718   
719    /**
720    * @since 1.2.9
721    * @return
722    */
 
723  7029930 toggle public static String toJSONString(Object object, //
724    SerializeConfig config, //
725    SerializeFilter[] filters, //
726    String dateFormat, //
727    int defaultFeatures, //
728    SerializerFeature... features) {
729  7029930 SerializeWriter out = new SerializeWriter(null, defaultFeatures, features);
730   
731  7029930 try {
732  7029930 JSONSerializer serializer = new JSONSerializer(out, config);
733   
734  7029930 if (dateFormat != null && dateFormat.length() != 0) {
735  21 serializer.setDateFormat(dateFormat);
736  21 serializer.config(SerializerFeature.WriteDateUseDateFormat, true);
737    }
738   
739  7029930 if (filters != null) {
740  7029909 for (SerializeFilter filter : filters) {
741  356 serializer.addFilter(filter);
742    }
743    }
744   
745  7029930 serializer.write(object);
746   
747  7029919 return out.toString();
748    } finally {
749  7029930 out.close();
750    }
751    }
752   
753    /**
754    * @deprecated
755    */
 
756  13 toggle public static String toJSONStringZ(Object object, SerializeConfig mapping, SerializerFeature... features) {
757  13 return toJSONString(object, mapping, emptyFilters, null, 0, features);
758    }
759   
760    /**
761    * @since 1.2.42
762    */
 
763  2 toggle public static byte[] toJSONBytes(Object object, SerializeConfig config, SerializerFeature... features) {
764  2 return toJSONBytes(object, config, emptyFilters, DEFAULT_GENERATE_FEATURE, features);
765    }
766   
767    /**
768    * @since 1.2.11
769    */
 
770  79 toggle public static byte[] toJSONBytes(Object object, SerializeConfig config, int defaultFeatures, SerializerFeature... features) {
771  79 return toJSONBytes(object, config, emptyFilters, defaultFeatures, features);
772    }
773   
774    /**
775    * @since 1.2.42
776    */
 
777  1 toggle public static byte[] toJSONBytes(Object object, SerializeFilter[] filters, SerializerFeature... features) {
778  1 return toJSONBytes(object, SerializeConfig.globalInstance, filters, DEFAULT_GENERATE_FEATURE, features);
779    }
780   
 
781  5 toggle public static byte[] toJSONBytes(Object object, SerializeConfig config, SerializeFilter filter, SerializerFeature... features) {
782  5 return toJSONBytes(object, config, new SerializeFilter[] {filter}, DEFAULT_GENERATE_FEATURE, features);
783    }
784   
785    /**
786    * @since 1.2.42
787    */
 
788  104 toggle public static byte[] toJSONBytes(Object object, SerializeConfig config, SerializeFilter[] filters, int defaultFeatures, SerializerFeature... features) {
789  104 return toJSONBytes(object, config, filters, null, defaultFeatures, features);
790    }
791   
792    /**
793    * @since 1.2.55
794    */
 
795  106 toggle public static byte[] toJSONBytes(Object object, SerializeConfig config, SerializeFilter[] filters, String dateFormat, int defaultFeatures, SerializerFeature... features) {
796  106 return toJSONBytes(IOUtils.UTF8, object, config, filters, dateFormat, defaultFeatures, features);
797    }
798   
799    /**
800    * @since 1.2.55
801    */
 
802  113 toggle public static byte[] toJSONBytes(Charset charset, //
803    Object object, //
804    SerializeConfig config, //
805    SerializeFilter[] filters, //
806    String dateFormat, //
807    int defaultFeatures, //
808    SerializerFeature... features) {
809  113 SerializeWriter out = new SerializeWriter(null, defaultFeatures, features);
810   
811  113 try {
812  113 JSONSerializer serializer = new JSONSerializer(out, config);
813   
814  113 if (dateFormat != null && dateFormat.length() != 0) {
815  2 serializer.setDateFormat(dateFormat);
816  2 serializer.config(SerializerFeature.WriteDateUseDateFormat, true);
817    }
818   
819  113 if (filters != null) {
820  113 for (SerializeFilter filter : filters) {
821  25 serializer.addFilter(filter);
822    }
823    }
824   
825  113 serializer.write(object);
826  105 return out.toBytes(charset);
827    } finally {
828  113 out.close();
829    }
830    }
831   
 
832  14 toggle public static String toJSONString(Object object, boolean prettyFormat) {
833  14 if (!prettyFormat) {
834  3 return toJSONString(object);
835    }
836   
837  11 return toJSONString(object, SerializerFeature.PrettyFormat);
838    }
839   
840    /**
841    * @deprecated use writeJSONString
842    */
 
843  16 toggle public static void writeJSONStringTo(Object object, Writer writer, SerializerFeature... features) {
844  16 writeJSONString(writer, object, features);
845    }
846   
847    /**
848    * This method serializes the specified object into its equivalent json representation.
849    *
850    * @param writer Writer to which the json representation needs to be written
851    * @param object the object for which json representation is to be created setting for fastjson
852    * @param features serializer features
853    * @since 1.2.11
854    */
 
855  26 toggle public static void writeJSONString(Writer writer, Object object, SerializerFeature... features) {
856  26 writeJSONString(writer, object, JSON.DEFAULT_GENERATE_FEATURE, features);
857    }
858   
859    /**
860    * @since 1.2.11
861    */
 
862  26 toggle public static void writeJSONString(Writer writer, Object object, int defaultFeatures, SerializerFeature... features) {
863  26 SerializeWriter out = new SerializeWriter(writer, defaultFeatures, features);
864   
865  26 try {
866  26 JSONSerializer serializer = new JSONSerializer(out);
867  26 serializer.write(object);
868    } finally {
869  26 out.close();
870    }
871    }
872   
873    /**
874    * write object as json to OutputStream
875    * @param os output stream
876    * @param object
877    * @param features serializer features
878    * @since 1.2.11
879    * @throws IOException
880    */
 
881  5 toggle public static final int writeJSONString(OutputStream os, //
882    Object object, //
883    SerializerFeature... features) throws IOException {
884  5 return writeJSONString(os, object, DEFAULT_GENERATE_FEATURE, features);
885    }
886   
887    /**
888    * @since 1.2.11
889    */
 
890  9 toggle public static final int writeJSONString(OutputStream os, //
891    Object object, //
892    int defaultFeatures, //
893    SerializerFeature... features) throws IOException {
894  9 return writeJSONString(os, //
895    IOUtils.UTF8, //
896    object, //
897    SerializeConfig.globalInstance, //
898    null, //
899    null, //
900    defaultFeatures, //
901    features);
902    }
903   
 
904  2 toggle public static final int writeJSONString(OutputStream os, //
905    Charset charset, //
906    Object object, //
907    SerializerFeature... features) throws IOException {
908  2 return writeJSONString(os, //
909    charset, //
910    object, //
911    SerializeConfig.globalInstance, //
912    null, //
913    null, //
914    DEFAULT_GENERATE_FEATURE, //
915    features);
916    }
917   
 
918  106 toggle public static final int writeJSONString(OutputStream os, //
919    Charset charset, //
920    Object object, //
921    SerializeConfig config, //
922    SerializeFilter[] filters, //
923    String dateFormat, //
924    int defaultFeatures, //
925    SerializerFeature... features) throws IOException {
926  106 SerializeWriter writer = new SerializeWriter(null, defaultFeatures, features);
927   
928  106 try {
929  106 JSONSerializer serializer = new JSONSerializer(writer, config);
930   
931  106 if (dateFormat != null && dateFormat.length() != 0) {
932  9 serializer.setDateFormat(dateFormat);
933  9 serializer.config(SerializerFeature.WriteDateUseDateFormat, true);
934    }
935   
936  106 if (filters != null) {
937  95 for (SerializeFilter filter : filters) {
938  35 serializer.addFilter(filter);
939    }
940    }
941   
942  106 serializer.write(object);
943   
944  104 int len = writer.writeToEx(os, charset);
945  96 return len;
946    } finally {
947  106 writer.close();
948    }
949    }
950   
951    // ======================================
 
952  121 toggle @Override
953    public String toString() {
954  121 return toJSONString();
955    }
956   
 
957  179 toggle public String toJSONString() {
958  179 SerializeWriter out = new SerializeWriter();
959  179 try {
960  179 new JSONSerializer(out).write(this);
961  179 return out.toString();
962    } finally {
963  179 out.close();
964    }
965    }
966   
967    /**
968    * @since 1.2.57
969    */
 
970  1 toggle public String toString(SerializerFeature... features) {
971  1 SerializeWriter out = new SerializeWriter(null, JSON.DEFAULT_GENERATE_FEATURE, features);
972   
973  1 try {
974  1 new JSONSerializer(out).write(this);
975  1 return out.toString();
976    } finally {
977  1 out.close();
978    }
979    }
980   
 
981  6 toggle public void writeJSONString(Appendable appendable) {
982  6 SerializeWriter out = new SerializeWriter();
983  6 try {
984  6 new JSONSerializer(out).write(this);
985  6 appendable.append(out.toString());
986    } catch (IOException e) {
987  1 throw new JSONException(e.getMessage(), e);
988    } finally {
989  6 out.close();
990    }
991    }
992   
993    /**
994    * This method serializes the specified object into its equivalent representation as a tree of
995    * {@link JSONObject}s.
996    *
997    */
 
998  1010229 toggle public static Object toJSON(Object javaObject) {
999  1010229 return toJSON(javaObject, SerializeConfig.globalInstance);
1000    }
1001   
1002    /**
1003    * @deprecated
1004    */
 
1005  2 toggle public static Object toJSON(Object javaObject, ParserConfig parserConfig) {
1006  2 return toJSON(javaObject, SerializeConfig.globalInstance);
1007    }
1008   
 
1009  1010712 toggle @SuppressWarnings("unchecked")
1010    public static Object toJSON(Object javaObject, SerializeConfig config) {
1011  1010712 if (javaObject == null) {
1012  19 return null;
1013    }
1014   
1015  1010693 if (javaObject instanceof JSON) {
1016  2 return javaObject;
1017    }
1018   
1019  1010691 if (javaObject instanceof Map) {
1020  9 Map<Object, Object> map = (Map<Object, Object>) javaObject;
1021   
1022  9 int size = map.size();
1023   
1024  9 Map innerMap;
1025  9 if (map instanceof LinkedHashMap) {
1026  1 innerMap = new LinkedHashMap(size);
1027  8 } else if (map instanceof TreeMap) {
1028  0 innerMap = new TreeMap();
1029    } else {
1030  8 innerMap = new HashMap(size);
1031    }
1032   
1033  9 JSONObject json = new JSONObject(innerMap);
1034   
1035  9 for (Map.Entry<Object, Object> entry : map.entrySet()) {
1036  14 Object key = entry.getKey();
1037  14 String jsonKey = TypeUtils.castToString(key);
1038  14 Object jsonValue = toJSON(entry.getValue(), config);
1039  14 json.put(jsonKey, jsonValue);
1040    }
1041   
1042  9 return json;
1043    }
1044   
1045  1010682 if (javaObject instanceof Collection) {
1046  9 Collection<Object> collection = (Collection<Object>) javaObject;
1047   
1048  9 JSONArray array = new JSONArray(collection.size());
1049   
1050  9 for (Object item : collection) {
1051  20 Object jsonValue = toJSON(item, config);
1052  20 array.add(jsonValue);
1053    }
1054   
1055  9 return array;
1056    }
1057   
1058  1010673 if (javaObject instanceof JSONSerializable) {
1059  1 String json = JSON.toJSONString(javaObject);
1060  1 return JSON.parse(json);
1061    }
1062   
1063  1010672 Class<?> clazz = javaObject.getClass();
1064   
1065  1010672 if (clazz.isEnum()) {
1066  1 return ((Enum<?>) javaObject).name();
1067    }
1068   
1069  1010671 if (clazz.isArray()) {
1070  10107 int len = Array.getLength(javaObject);
1071   
1072  10107 JSONArray array = new JSONArray(len);
1073   
1074  1020282 for (int i = 0; i < len; ++i) {
1075  1010175 Object item = Array.get(javaObject, i);
1076  1010175 Object jsonValue = toJSON(item);
1077  1010175 array.add(jsonValue);
1078    }
1079   
1080  10107 return array;
1081    }
1082   
1083  1000564 if (ParserConfig.isPrimitive2(clazz)) {
1084  1000441 return javaObject;
1085    }
1086   
1087  123 ObjectSerializer serializer = config.getObjectWriter(clazz);
1088  123 if (serializer instanceof JavaBeanSerializer) {
1089  115 JavaBeanSerializer javaBeanSerializer = (JavaBeanSerializer) serializer;
1090   
1091  115 JSONObject json = new JSONObject();
1092  115 try {
1093  115 Map<String, Object> values = javaBeanSerializer.getFieldValuesMap(javaObject);
1094  114 for (Map.Entry<String, Object> entry : values.entrySet()) {
1095  440 json.put(entry.getKey(), toJSON(entry.getValue(), config));
1096    }
1097    } catch (Exception e) {
1098  1 throw new JSONException("toJSON error", e);
1099    }
1100  114 return json;
1101    }
1102   
1103  8 String text = JSON.toJSONString(javaObject);
1104  8 return JSON.parse(text);
1105    }
1106   
 
1107  21 toggle public static <T> T toJavaObject(JSON json, Class<T> clazz) {
1108  21 return TypeUtils.cast(json, clazz, ParserConfig.getGlobalInstance());
1109    }
1110   
1111    /**
1112    * @since 1.2.9
1113    */
 
1114  4 toggle public <T> T toJavaObject(Class<T> clazz) {
1115  4 if (clazz == JSONArray.class || clazz == JSON.class || clazz == Collection.class || clazz == List.class) {
1116  4 return (T) this;
1117    }
1118   
1119  0 return TypeUtils.cast(this, clazz, ParserConfig.getGlobalInstance());
1120    }
1121   
1122    /**
1123    * @since 1.2.33
1124    */
 
1125  13 toggle public <T> T toJavaObject(Type type) {
1126  13 return TypeUtils.cast(this, type, ParserConfig.getGlobalInstance());
1127    }
1128   
1129    /**
1130    * @since 1.2.33
1131    */
 
1132  2 toggle public <T> T toJavaObject(TypeReference typeReference) {
1133  2 Type type = typeReference != null ? typeReference.getType() : null;
1134  2 return TypeUtils.cast(this, type, ParserConfig.getGlobalInstance());
1135    }
1136   
1137    private final static ThreadLocal<byte[]> bytesLocal = new ThreadLocal<byte[]>();
 
1138  56 toggle private static byte[] allocateBytes(int length) {
1139  56 byte[] chars = bytesLocal.get();
1140   
1141  56 if (chars == null) {
1142  6 if (length <= 1024 * 64) {
1143  6 chars = new byte[1024 * 64];
1144  6 bytesLocal.set(chars);
1145    } else {
1146  0 chars = new byte[length];
1147    }
1148  50 } else if (chars.length < length) {
1149  0 chars = new byte[length];
1150    }
1151   
1152  56 return chars;
1153    }
1154   
1155    private final static ThreadLocal<char[]> charsLocal = new ThreadLocal<char[]>();
 
1156  94 toggle private static char[] allocateChars(int length) {
1157  94 char[] chars = charsLocal.get();
1158   
1159  94 if (chars == null) {
1160  12 if (length <= 1024 * 64) {
1161  11 chars = new char[1024 * 64];
1162  11 charsLocal.set(chars);
1163    } else {
1164  1 chars = new char[length];
1165    }
1166  82 } else if (chars.length < length) {
1167  2 chars = new char[length];
1168    }
1169   
1170  94 return chars;
1171    }
1172   
 
1173  50 toggle public static boolean isValid(String str) {
1174  50 if (str == null || str.length() == 0) {
1175  4 return false;
1176    }
1177   
1178  46 JSONScanner lexer = new JSONScanner(str);
1179  46 try {
1180  46 lexer.nextToken();
1181   
1182  42 final int token = lexer.token();
1183  42 switch (token) {
1184  12 case JSONToken.LBRACE:
1185  12 if (lexer.getCurrent() == JSONLexer.EOI) {
1186  1 return false;
1187    }
1188  11 lexer.skipObject(true);
1189  8 break;
1190  14 case JSONToken.LBRACKET:
1191  14 lexer.skipArray(true);
1192  8 break;
1193  3 case JSONToken.LITERAL_INT:
1194  2 case JSONToken.LITERAL_STRING:
1195  3 case JSONToken.LITERAL_FLOAT:
1196  0 case JSONToken.LITERAL_ISO8601_DATE:
1197  2 case JSONToken.NULL:
1198  2 case JSONToken.TRUE:
1199  2 case JSONToken.FALSE:
1200  14 lexer.nextToken();
1201  14 break;
1202  2 default:
1203  2 return false;
1204    }
1205   
1206  30 return lexer.token() == JSONToken.EOF;
1207    } catch (Exception ex) {
1208  13 return false;
1209    } finally {
1210  46 lexer.close();
1211    }
1212    }
1213   
 
1214  10 toggle public static boolean isValidObject(String str) {
1215  10 if (str == null || str.length() == 0) {
1216  0 return false;
1217    }
1218   
1219  10 JSONScanner lexer = new JSONScanner(str);
1220   
1221  10 try {
1222  10 lexer.nextToken();
1223  10 final int token = lexer.token();
1224  10 if (token == JSONToken.LBRACE) {
1225  10 if (lexer.getCurrent() == JSONLexer.EOI) {
1226  1 return false;
1227    }
1228  9 lexer.skipObject(true);
1229  6 return lexer.token() == JSONToken.EOF;
1230    }
1231  0 return false;
1232    } catch (Exception ex) {
1233  3 return false;
1234    } finally {
1235  10 lexer.close();
1236    }
1237    }
1238   
 
1239  12 toggle public static boolean isValidArray(String str) {
1240  12 if (str == null || str.length() == 0) {
1241  0 return false;
1242    }
1243   
1244  12 JSONScanner lexer = new JSONScanner(str);
1245  12 try {
1246  12 lexer.nextToken();
1247  12 final int token = lexer.token();
1248  12 if (token == JSONToken.LBRACKET) {
1249  12 lexer.skipArray(true);
1250  6 return lexer.token() == JSONToken.EOF;
1251    }
1252  0 return false;
1253    } catch (Exception ex) {
1254  6 return false;
1255    } finally {
1256  12 lexer.close();
1257    }
1258    }
1259   
 
1260  0 toggle public static <T> void handleResovleTask(DefaultJSONParser parser, T value) {
1261  0 parser.handleResovleTask(value);
1262    }
1263   
 
1264  19 toggle public static void addMixInAnnotations(Type target, Type mixinSource) {
1265  19 if (target != null && mixinSource != null) {
1266  19 mixInsMapper.put(target, mixinSource);
1267    }
1268    }
1269   
 
1270  21 toggle public static void removeMixInAnnotations(Type target) {
1271  21 if (target != null) {
1272  21 mixInsMapper.remove(target);
1273    }
1274    }
1275   
 
1276  1 toggle public static void clearMixInAnnotations() {
1277  1 mixInsMapper.clear();
1278    }
1279   
 
1280  58253889 toggle public static Type getMixInAnnotations(Type target) {
1281  58253889 if (target != null) {
1282  58253888 return mixInsMapper.get(target);
1283    }
1284  2 return null;
1285    }
1286   
1287    public final static String VERSION = "1.2.61";
1288    }